package ATM.frame;

import ATM.pojo.UserDO;
import ATM.util.Util;
import ATM.util.UtilSql1;

import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;

public class ATMJframe extends JFrame {

    private Image background = Util.getimages("/images/background.jpg");
    private ArrayList<UserDO> usersArrayList = new ArrayList();
    private UtilSql1 test01 = new UtilSql1();


    private LogJpanel logJpanel = new LogJpanel(this);
    private MenuJpanel menuJpanel = new MenuJpanel(this);
    private SaveJpanel saveJpanel = new SaveJpanel(this);
    private FindJpanel findJpanel = new FindJpanel(this);
    private GetJpanel getJpanel = new GetJpanel(this);
    private PassWordModifyJpanel passWordChangeJpanel = new PassWordModifyJpanel(this);
    private TransferJpanel transferJpanel = new TransferJpanel(this);
    private UserDO user;// 保存下标
    private CardLayout cardLayout = new CardLayout();


    public ATMJframe() {

        this.setContentPane(new JPanel() {
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                g.drawImage(background, 0, 0, 1042, 768, this);
            }
        });
//        init();
        this.setLayout(cardLayout);
        this.add("log", logJpanel);
        this.add("menu", menuJpanel);
        this.add("save", saveJpanel);
        this.add("find", findJpanel);
        this.add("get", getJpanel);
        this.add("trans", transferJpanel);
        this.add("modify", passWordChangeJpanel);


        this.setSize(1042, 768);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setTitle("ATM");
        this.setVisible(true);
    }


    public static void main(String[] args) {
        ATMJframe abc = new ATMJframe();
    }

//    public void init() {
//        usersArrayList = (ArrayList<Users>) test01.query();
//
//
//
//
//
//
////        usersArrayList.add(new Users("aaaaaa", "111111", 10000));
////        usersArrayList.add(new Users("bbbbbb", "222222", 20000));
////        usersArrayList.add(new Users("cccccc", "333333", 30000));
////        usersArrayList.add(new Users("dddddd", "444444", 40000));
////        usersArrayList.add(new Users("eeeeee", "555555", 50000));
//
////        this.usersArrayList = (ArrayList)FileUtil.readObject("a.dat");
//
//
//    }

    public ArrayList<UserDO> getUsersArrayList() {
        return usersArrayList;
    }

    public void setUsersArrayList(ArrayList<UserDO> usersArrayList) {
        this.usersArrayList = usersArrayList;
    }

    public void switchPanel(String name) {
        cardLayout.show(this.getContentPane(), name);
    }

    public void setFindJpanel() {
        getFindJpanel().getYueLabel().setText("余额为" + getUser().getCount());

    }


    public UserDO getUser() {
        return user;
    }

    public void setUser(UserDO user) {
        this.user = user;
    }

    public PassWordModifyJpanel getPassWordChangeJpanel() {
        return passWordChangeJpanel;
    }

    public TransferJpanel getTransferJpanel() {
        return transferJpanel;
    }

    public LogJpanel getLogJpanel() {
        return logJpanel;
    }

    public MenuJpanel getMenuJpanel() {
        return menuJpanel;
    }

    public SaveJpanel getSaveJpanel() {
        return saveJpanel;
    }

    public FindJpanel getFindJpanel() {
        return findJpanel;
    }

    public GetJpanel getGetJpanel() {
        return getJpanel;
    }

    public UtilSql1 getTest01() {
        return test01;
    }

    public void setTest01(UtilSql1 test01) {
        this.test01 = test01;
    }
}
